package graphics;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;

import ship.Ship;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ShipControlPanel extends JPanel {
	private Ship ship;
	/**
	 * Create the panel.
	 */
	private JProgressBar shieldBar;

	private JComboBox leftTube;
	private int previousLeftIndex = 0;
	private JProgressBar leftProgressBar;
	
	private JComboBox rightTube;
	private int previousRightIndex = 0;
	private JProgressBar rightProgressBar;
	
	private JComboBox centerTube;
	private int previousCenterIndex = 0;
	private JProgressBar centerProgressBar;
	
	
	
	public ShipControlPanel(Ship s) {
		ship = s;

		setLayout(null);

		JLabel static1 = new JLabel("New label");
		static1.setIcon(new ImageIcon("/Users/max/Documents/workspace/NewestGame/images/static1.png"));
		static1.setBounds(0, 0, 434, 57);
		add(static1);

		JLabel static3 = new JLabel("New label");
		static3.setIcon(new ImageIcon("/Users/max/Documents/workspace/NewestGame/images/static1.png"));
		static3.setBounds(0, 502, 376, 50);
		add(static3);

		JLabel static2 = new JLabel("New label");
		static2.setIcon(new ImageIcon("/Users/max/Documents/workspace/NewestGame/images/static1.png"));
		static2.setBounds(373, 52, 61, 500);
		add(static2);

		JLabel shipStatusLabel = new JLabel("");
		shipStatusLabel.setBounds(62, 93, 266, 145);
		add(shipStatusLabel);

		leftTube = new JComboBox();
		leftTube.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(leftTube.getSelectedIndex() != previousLeftIndex) {
					ship.changeLeftTube(leftTube.getSelectedIndex());
					previousLeftIndex = leftTube.getSelectedIndex();
				}
			}
		});
		leftTube.setBounds(77, 250, 89, 27);
		add(leftTube);

		JLabel lblNewLabel = new JLabel("Left Tube:");
		lblNewLabel.setBounds(6, 254, 92, 16);
		add(lblNewLabel);

		JLabel lblRightTube = new JLabel("Right Tube:");
		lblRightTube.setBounds(189, 254, 61, 16);
		add(lblRightTube);

		rightTube = new JComboBox();
		rightTube.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(rightTube.getSelectedIndex() != previousRightIndex) {
					ship.changeRightTube(rightTube.getSelectedIndex());
					previousRightIndex = rightTube.getSelectedIndex();
				}
			}
		});
		rightTube.setBounds(262, 250, 84, 27);
		add(rightTube);

		JLabel lblSpecial = new JLabel("Special:");
		lblSpecial.setBounds(88, 314, 61, 16);
		add(lblSpecial);

		JComboBox specialTube = new JComboBox();
		specialTube.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(centerTube.getSelectedIndex() != previousCenterIndex) {
					ship.changeCenterTube(centerTube.getSelectedIndex());
					previousCenterIndex = centerTube.getSelectedIndex();
				}
			}
		});
		specialTube.setBounds(150, 310, 89, 27);
		add(specialTube);

		leftProgressBar = new JProgressBar();
		leftProgressBar.setBounds(16, 275, 150, 27);
		add(leftProgressBar);

		rightProgressBar = new JProgressBar();
		rightProgressBar.setBounds(199, 275, 147, 27);
		add(rightProgressBar);

		centerProgressBar = new JProgressBar();
		centerProgressBar.setBounds(88, 342, 151, 27);
		add(centerProgressBar);

		JLabel miniMap = new JLabel("");
		miniMap.setBounds(70, 342, 258, 137);
		add(miniMap);

		shieldBar = new JProgressBar();
		shieldBar.setStringPainted(true);
		shieldBar.setBounds(31, 69, 315, 20);
		add(shieldBar);

	}
	
	public void update() {
		shieldBar.setValue((int) (ship.getShields() * 100));
		leftProgressBar.setValue(ship.getTimeLeft());
		rightProgressBar.setValue(ship.getTimeRight());
		centerProgressBar.setValue(ship.getTimeCenter());
		
	}
}
